package com.zj.rocketmq.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisService {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    final static String WATCH_KEY = "RESTCOUT";


    public boolean activityGoingOn() {
        try {
            redisTemplate.watch(WATCH_KEY);
            String s = redisTemplate.opsForValue().get(WATCH_KEY);
            Integer rest = Integer.valueOf(s);
            if (rest > 0) {
                redisTemplate.opsForValue().decrement(WATCH_KEY);
                return true;
            }else{
                return false;
            }
        } finally {
            redisTemplate.multi();
        }
    }
}
